#include <cstdio>
#include <cstring>

int fac[ 1300 ][ 10000 ], h[ 10000 ], pr[ 1300 ], cnt;
bool visit[ 10000 ];

void initprime( )
{
    int i, j;
    memset( visit, 1, sizeof( visit ) );
    for ( i = 2; i < 10000; i++ )
        if ( visit[ i ] )
        {
            h[ i ] = cnt;
            pr[ cnt++ ] = i;
            for ( j = i * 2; j < 10000; j += i )
                visit[ j ] = 0;
        }
}

void init( )
{
    int i, j;
    for ( i = 0; i < cnt; i++ )
    {
        fac[ i ][ 0 ] = 1;
        for ( j = 1; j < pr[ i ]; j++ )
            fac[ i ][ j ] = fac[ i ][ j - 1 ] * j % pr[ i ];
    }
}

int mypow( int x, int n, int p )
{
    int ret = 1, pos = 1;
    while ( pos <= n ) pos <<= 1;
    pos >>= 1;
    while ( pos )
    {
        ret = ret * ret % p;
        if ( pos & n ) ret = ret * x % p;
        pos >>= 1;
    }
    return ret;
}

int C( int n, int m, int p, int *fac )
{
    if ( m > n ) return 0;
    return fac[ n ] * mypow( fac[ n - m ] * fac[ m ] % p, p - 2, p ) % p;
}

int lucas( int n, int m, int p, int *fac )
{
    if ( m == 0 ) return 1;
    return lucas( n / p, m / p, p, fac ) * C( n % p, m % p, p, fac ) % p;
}

int main( )
{
    int n, m, p, cas = 1;
    initprime( );
    init( );
    while ( scanf("%d%d%d", &n, &m, &p) != EOF )
    {
        printf("Case #%d: ", cas++);
        if ( m > n - m ) m = n - m;
        if ( m == 0 )
        {
            printf("%d\n", ( n + 1 ) % p);
            continue;
        }
        printf("%d\n", ( lucas( n + 1, m, p, fac[ h[ p ] ] ) + n - m ) % p);
    }
    return 0;
}
